package com.suzao.rabbitmq.config;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @classname: RabbitConfig
 * @description:
 * @author: mc
 * @create: 2020-10-29 15:21
 **/
@Configuration
public class RabbitConfig {

    /**
    * @Description: 所有的消息发送都会转换成JSON格式发到交换机
    * @Param: [connectionFactory]
    * @return: RabbitTemplate
    * @Author: mc
    * @Date: 2020/10/29
    */
    @Bean
    public RabbitTemplate suzaoTemplate(final ConnectionFactory connectionFactory){
        final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        return rabbitTemplate;
    }
}
